| Conditions | 3 |
| Total Lines | 16 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' |
||
| 5 | public async login({ auth, request }: HttpContextContract) |
||
| 6 | { |
||
| 7 | const payload = await LoginRequest.validate(request) |
||
| 8 | if (payload.hasOwnProperty('errors')) { |
||
| 9 | return payload |
||
| 10 | } |
||
| 11 | |||
| 12 | try { |
||
| 13 | const token = await auth.use('api').attempt(payload.email, payload.password) |
||
| 14 | return { |
||
| 15 | accessToken: token, |
||
| 16 | user: auth.use('api').user |
||
| 17 | } |
||
| 18 | } catch { |
||
| 19 | return { |
||
| 20 | errors: 'Invalid credentials' |
||
| 21 | } |
||
| 25 |